home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
-
- Gnucleus - A node application for the Gnutella network
- Copyright (C) 2000 John Marshall
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- For support, questions, comments, etc...
- E-Mail:
- swabby@c0re.net
-
- Address:
- 21 Cadogan Way
- Nashua, NH, USA 03062
-
- ********************************************************************************/
-
- // ViewNode.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "Gnucleus.h"
-
- #include "GnucleusDoc.h"
- #include "ViewSearch.h"
- #include "ViewNode.h"
-
- #include "GnuTransfer.h"
- #include "GnuHash.h"
- #include "GnuSock.h"
- #include "GnuControl.h"
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewNode
-
- IMPLEMENT_DYNCREATE(CViewNode, CFormView)
-
- CViewNode::CViewNode()
- : CFormView(CViewNode::IDD)
- {
- //{{AFX_DATA_INIT(CViewNode)
- m_strNodeBadStat = _T("");
- m_strNodeRecivedStat = _T("");
- m_strNodeSentStat = _T("");
- //}}AFX_DATA_INIT
- }
-
- CViewNode::~CViewNode()
- {
- }
-
- void CViewNode::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CViewNode)
- DDX_Control(pDX, IDC_CHK_QUERYHITS, m_chkQueryHits);
- DDX_Control(pDX, IDC_CHK_PUSHES, m_chkPushes);
- DDX_Control(pDX, IDC_CHK_UNKNOWNS, m_chkUnknowns);
- DDX_Control(pDX, IDC_CHK_TTL, m_chkTTL);
- DDX_Control(pDX, IDC_CHK_QUERIES, m_chkQueries);
- DDX_Control(pDX, IDC_CHK_PONGS, m_chkPongs);
- DDX_Control(pDX, IDC_CHK_DROPPED, m_chkDropped);
- DDX_Control(pDX, IDC_CHK_GUID, m_chkGUID);
- DDX_Control(pDX, IDC_CHK_HOPS, m_chkHops);
- DDX_Control(pDX, IDC_CHK_PAYLOAD, m_chkPayload);
- DDX_Control(pDX, IDC_CHK_PINGS, m_chkPings);
- DDX_Control(pDX, IDC_EDT_LOG, m_ebLog);
- DDX_Text(pDX, IDC_VIEW_NODE_BAD_STAT, m_strNodeBadStat);
- DDX_Text(pDX, IDC_VIEW_NODE_RECIVED_STAT, m_strNodeRecivedStat);
- DDX_Text(pDX, IDC_VIEW_NODE_SENT_STAT, m_strNodeSentStat);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CViewNode, CFormView)
- //{{AFX_MSG_MAP(CViewNode)
- ON_WM_SIZE()
- ON_WM_TIMER()
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_CHK_PINGS, OnChkPings)
- ON_BN_CLICKED(IDC_CHK_PONGS, OnChkPongs)
- ON_BN_CLICKED(IDC_CHK_QUERIES, OnChkQueries)
- ON_BN_CLICKED(IDC_CHK_QUERYHITS, OnChkQueryhits)
- ON_BN_CLICKED(IDC_CHK_UNKNOWNS, OnChkUnknowns)
- ON_BN_CLICKED(IDC_CHK_GUID, OnChkGuid)
- ON_BN_CLICKED(IDC_CHK_HOPS, OnChkHops)
- ON_BN_CLICKED(IDC_CHK_TTL, OnChkTtl)
- ON_BN_CLICKED(IDC_CHK_PAYLOAD, OnChkPayload)
- ON_BN_CLICKED(IDC_CHK_DROPPED, OnChkDropped)
- ON_BN_CLICKED(IDC_CHK_PUSHES, OnChkPushes)
- ON_BN_CLICKED(IDC_BUTTON_FLUSH, OnButtonFlush)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewNode diagnostics
-
- #ifdef _DEBUG
- void CViewNode::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CViewNode::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewNode message handlers
-
- void CViewNode::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- // Get node address and port from the title
- CString Title;
- GetParentFrame()->GetWindowText(Title);
-
- Title.Delete(0, 5);
- HostPort = Title;
-
- Node = ((CGnucleusDoc *) GetDocument())->GnuComm->GetNode(HostPort);
-
- if(Node != NULL)
- Node->Log = "";
-
- // Set the time to update the log
- UpdateTimer = SetTimer(1, 500, 0);
-
- // Resize the window so all the controls adjust properly
- CRect rect;
-
- GetParentFrame()->GetClientRect(&rect);
- OnSize(SIZE_RESTORED, rect.right - 4, rect.bottom - 4);
- }
-
- void CViewNode::OnSize(UINT nType, int cx, int cy)
- {
- if(m_ebLog.m_hWnd != NULL)
- {
- int top, left;
-
- LPRECT wndRect = new RECT,
- ctrlRect = new RECT;
-
- GetWindowRect(wndRect);
- m_ebLog.GetWindowRect(ctrlRect);
-
- top = ctrlRect->top - wndRect->top - 2;
- left = ctrlRect->left - wndRect->left - 2;
-
- m_ebLog.MoveWindow(left, top, cx - left - 7, cy - top - 7);
-
- delete wndRect;
- delete ctrlRect;
- }
-
- CFormView::OnSize(nType, cx, cy);
- }
-
- void CViewNode::OnTimer(UINT nIDEvent)
- {
-
- if(nIDEvent == UpdateTimer)
- {
- Node = ((CGnucleusDoc *) GetDocument())->GnuComm->GetNode(HostPort);
-
- if(Node != NULL)
- {
- // Update the main edit box
- CString Log = Node->Log, PastLog;
- Node->Log = "";
-
- m_strNodeBadStat.Format("%u", Node->m_dwNumOfBadPackets);
- m_strNodeRecivedStat.Format("%u", Node->m_dwNumOfRecivedPackets);
- m_strNodeSentStat.Format("%u", Node->m_dwNumOfSentPackets);
-
- UpdateData(FALSE);
-
- m_ebLog.GetWindowText(PastLog);
-
- if(PastLog.GetLength() > 10000)
- Log += PastLog.Left(10000);
- else
- Log += PastLog;
-
- m_ebLog.SetWindowText(Log);
-
- //Check the checks, sometimes its missed at start up
- Node->logPings = m_chkPings.GetCheck() ? 1 : 0;
- Node->logPongs = m_chkPongs.GetCheck() ? 1 : 0;
- Node->logPushes = m_chkPushes.GetCheck() ? 1 : 0;
- Node->logQueries = m_chkQueries.GetCheck() ? 1 : 0;
- Node->logQueryReplies = m_chkQueryHits.GetCheck() ? 1 : 0;
- Node->logUnknowns = m_chkUnknowns.GetCheck() ? 1 : 0;
- }
- else // close the window
- {
- SendMessage(WM_CLOSE);
- //DestroyWindow();
- return; // can't call OnTimer after a destrywindow();
- }
-
- }
-
- CFormView::OnTimer(nIDEvent);
- }
-
- void CViewNode::OnClose()
- {
- Node = ((CGnucleusDoc *) GetDocument())->GnuComm->GetNode(HostPort);
-
- if(Node != NULL)
- {
- Node->logPings = Node->logPongs = Node->logQueries =
- Node->logPushes = Node->logQueryReplies = Node->logUnknowns =
- Node->logGUID = Node->logHops = Node->logTTL = Node->logPayload =
- Node->logDropped = 0;
-
- Node->Log = "";
- }
-
- CFormView::OnClose();
- }
-
- void CViewNode::OnChkPings()
- {
- if(Node != NULL)
- Node->logPings = m_chkPings.GetCheck() ? 1 : 0;
- }
- void CViewNode::OnChkPongs()
- {
- if(Node != NULL)
- Node->logPongs = m_chkPongs.GetCheck() ? 1 : 0;
- }
-
- void CViewNode::OnChkPushes()
- {
- if(Node != NULL)
- Node->logPushes = m_chkPushes.GetCheck() ? 1 : 0;}
-
- void CViewNode::OnChkQueries()
- {
- if(Node != NULL)
- Node->logQueries = m_chkQueries.GetCheck() ? 1 : 0;
- }
-
- void CViewNode::OnChkQueryhits()
- {
- if(Node != NULL)
- Node->logQueryReplies = m_chkQueryHits.GetCheck() ? 1 : 0;
- }
-
- void CViewNode::OnChkUnknowns()
- {
- if(Node != NULL)
- Node->logUnknowns = m_chkUnknowns.GetCheck() ? 1 : 0;}
-
- void CViewNode::OnChkGuid()
- {
- if(Node != NULL)
- Node->logGUID = m_chkGUID.GetCheck() ? 1 : 0;
- }
-
- void CViewNode::OnChkHops()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void CViewNode::OnChkTtl()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void CViewNode::OnChkPayload()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void CViewNode::OnChkDropped()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void CViewNode::OnButtonFlush()
- {
- m_ebLog.SetWindowText("");
- }
-